package com.yhp.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.system.comm.util.JsonUtils;
import com.system.common.pojo.BisNurseBag;
import com.yhp.service.FrontBisNurseBagService;

@Controller
@RequestMapping("fbnb")
public class FrontBisNurseBagController {
	@Autowired
	private FrontBisNurseBagService bagService;
	
	@RequestMapping("front-tend")
	public String tend(Model model,HttpServletRequest request){
		Map<String, Object> map = initMap(request);		
		List<BisNurseBag> bisNurseBag = bagService.selectByExample(map);
		model.addAttribute("bisNurseBag", bisNurseBag);
		return "bis_nurse/front-tend";
	}
	
	
	/**
	 * 综合查询
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping("front_bag")
	public String front_bag(Model model,HttpServletRequest request){
		Map<String, Object> map = initMap(request);
		List<BisNurseBag> bisNurseBag = bagService.selectByExample(map);
		model.addAttribute("bisNurseBag", bisNurseBag);
		return "bis_nurse/front_bag";
	}
	
	public Map<String, Object> initMap(HttpServletRequest request){
		Map<String, Object> map=new HashMap<>();
		String bagId=request.getParameter("bagId");
		String bagName=request.getParameter("bagName");
		String bagTotalPrice1=request.getParameter("bagTotalPrice1");
		String bagTotalPrice2=request.getParameter("bagTotalPrice2");
		if (bagId!=null&&!bagId.trim().equals("")) {
			map.put("bagId", bagId);
		}
		if (bagName!=null&&!bagName.trim().equals("")) {
			map.put("bagName", bagName);
		}
		if (bagTotalPrice1!=null&&!bagTotalPrice1.trim().equals("")) {
			map.put("bagTotalPrice1", bagTotalPrice1);
		}
		if (bagTotalPrice2!=null&&!bagTotalPrice2.trim().equals("")) {
			map.put("bagTotalPrice2", bagTotalPrice2);
		}
		return map;
	}
	
	/**
	 * 详情
	 * @param bagId
	 * @param model
	 * @return
	 */
	@RequestMapping(value="front_bag_details",produces = "application/json;charset=utf-8")
	@ResponseBody
	public String front_bag_details(HttpServletRequest request){
		String bagId=request.getParameter("bagId");
		BisNurseBag bisNurseBag = bagService.selectByPrimaryKey(bagId);
		return JsonUtils.toJson(bisNurseBag);
	}
}
